package com.my.mvpdemo.mvp2.presenter;

import com.my.mvpdemo.Girl;
import com.my.mvpdemo.mvp2.model.GirlModelImp1;
import com.my.mvpdemo.mvp2.model.IGirlModel;
import com.my.mvpdemo.mvp2.view.IGirlView;

import java.lang.ref.WeakReference;
import java.util.List;

/**
 * Created by 张英杰 on 2017/2/22.
 * 表示层 model和view 的桥梁
 */
public class GirlPresenter3 extends BasePresenter<IGirlView> {
   //Model引用
    IGirlModel girlModel = new GirlModelImp1();

    //加载数据  n取来
    public void fetch() {
        //显示进度条
        if (getView() != null) {
            getView().showLoading();
        }
        if (girlModel != null) {
            //加载数据
            girlModel.loadGirl(new IGirlModel.GirlOnLoadListerer() {
                @Override
                public void onComplete(List<Girl> girls) {
                    //返回数据
                    //显示到view层
                    IGirlView girlView = getView();
                    if (girlView != null) {
                        mViewRef.get().showGirls(girls);
                    }
                }
            });
        }
    }
}
